package com.yssw.client.controller;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yssw.model.vo.client.ClientUserSignLogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yssw.common.annotation.Log;
import com.yssw.common.core.controller.BaseController;
import com.yssw.common.core.domain.AjaxResult;
import com.yssw.common.enums.BusinessType;
import com.yssw.client.domain.ClientUserSignLog;
import com.yssw.client.service.IClientUserSignLogService;
import com.yssw.common.utils.poi.ExcelUtil;
import com.yssw.common.core.page.TableDataInfo;

/**
 * 用户签到记录Controller
 *
 * @author yssw
 * @date 2023-03-29
 */
@RestController
@RequestMapping("/client/signLog")
public class ClientUserSignLogController extends BaseController {
    @Autowired
    private IClientUserSignLogService clientUserSignLogService;

    /**
     * 查询用户签到记录列表
     */
    @PreAuthorize("@ss.hasPermi('client:signLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClientUserSignLog clientUserSignLog) {
        startPage();
        List<ClientUserSignLog> list = clientUserSignLogService.selectClientUserSignLogList(clientUserSignLog);
        return getDataTable(list);
    }

    /**
     * 根据用户id与月份获取用户签到记录
     */
//    @PreAuthorize("@ss.hasPermi('client:signLog:list')")
    @GetMapping("/listUser")
    public AjaxResult list(String month, Long userId) throws ParseException {

        return success(clientUserSignLogService
                .selectClientUserSignLogListByUserId(month, userId));
    }

    /**
     * 导出用户签到记录列表
     */
//    @PreAuthorize("@ss.hasPermi('client:signLog:export')")
    @Log(title = "用户签到记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClientUserSignLog clientUserSignLog) {
        List<ClientUserSignLog> list = clientUserSignLogService.selectClientUserSignLogList(clientUserSignLog);
        ExcelUtil<ClientUserSignLog> util = new ExcelUtil<ClientUserSignLog>(ClientUserSignLog.class);
        util.exportExcel(response, list, "用户签到记录数据");
    }

    /**
     * 获取用户签到记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('client:signLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(clientUserSignLogService.selectClientUserSignLogById(id));
    }

    /**
     * 新增用户签到记录
     */
//    @PreAuthorize("@ss.hasPermi('client:signLog:add')")
    @Log(title = "用户签到记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClientUserSignLog clientUserSignLog) {
        return toAjax(clientUserSignLogService.insertClientUserSignLog(clientUserSignLog));
    }

    /**
     * 修改用户签到记录
     */
//    @PreAuthorize("@ss.hasPermi('client:signLog:edit')")
    @Log(title = "用户签到记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClientUserSignLog clientUserSignLog) {
        return toAjax(clientUserSignLogService.updateClientUserSignLog(clientUserSignLog));
    }

    /**
     * 删除用户签到记录
     */
//    @PreAuthorize("@ss.hasPermi('client:signLog:remove')")
    @Log(title = "用户签到记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(clientUserSignLogService.deleteClientUserSignLogByIds(ids));
    }
}
